package com.sanchunhui.psc.data.respository

import com.sanchunhui.psc.data.api.ProjectTeamApi
import com.sanchunhui.psc.data.net.RetrofitFactory
import com.sanchunhui.psc.data.protocol.*
import rx.Observable
import javax.inject.Inject

/**
 * @Author zyx
 * @Date 2021/7/8-14:39
 * @Dscribe
 */
class ProjectTeamRepository @Inject constructor() {

    /*
        获取所在项⽬下所有分组
     */
    fun getTeamList(token: String) : Observable<ResponseInfo> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).getTeamList(TokenReq(token))
    }

    /*
         获取分组下所有成员
     */
    fun getTeamMember(teamID: Int, token: String): Observable<ResponseInfo> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).getTeamMember(teamID, TokenReq(token))
    }

    /*
    `    添加分组到所在项⽬
     */
    fun addTeam(token: String, name:String, leader_member_id:Int) : Observable<ResponseInfo> {
        return  RetrofitFactory.instance.create(ProjectTeamApi::class.java).addTeam(AddTeamReq(token, name, leader_member_id))
    }

    /*
        获取所有未在项⽬中⽤户的列表
     */
    fun searchMember(token: String, name: String?=null,company_id:Int?=null,job_id:Int?=null) : Observable<BaseResp<MutableList<UserInfo>?>> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).searchMember(SearchMemberReq(token,name,company_id,job_id))
    }

    /*
       获取所有公司组成的映射（键值对）
    */
    fun getCompanyList(token: String) : Observable<ResponseInfo> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).getCompanyList(TokenReq(token))
    }

    /*
        获取所有⼯种组成的映射（键值对）
     */
    fun getJobList(token: String) : Observable<ResponseInfo> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).getJobList(TokenReq(token))
    }


    /*
        更改分组状态
     */
    fun changeTeamStatus(teamId:Int, token: String, status:String) : Observable<BaseResp<String>> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).changeTeamStatus(teamId,TeamStatusReq(token, status))
    }

    /*
        添加成员到指定分组
     */
    fun addTeamMember(teamId: Int, token: String, ads:List<Int>) : Observable<BaseResp<String>> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).addTeamMember(teamId,TeamAddMemberReq(token, ads))
    }

    /*
        设置指定分组名称
     */
    fun setTeamInfo(teamId: Int, token: String, name: String) : Observable<BaseResp<String>>{
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).setTeamInfo(teamId,SetTeamInfoReq(token,name))
    }

    /*
        设置指定分组负责⼈
     */
    fun setTeamLeader(teamId: Int, token: String, id:Int) : Observable<BaseResp<String>> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).setTeamLeader(teamId, SetTeamLeaderReq(token,id))
    }

    /*
        移除项⽬（分组）中的成员
     */
    fun deleteMember(token: String, id:Int) : Observable<BaseResp<String>> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).deleteMember(DeleteMemberReq(token,id))
    }

    /*
       获取分组在线的成员ID
    */
    fun getOnlineMember(teamId: Int,token: String) : Observable<BaseResp<MutableList<Char>>> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).getOnlineMember(teamId, TokenReq(token))
    }

    /*
        获取所在或指定分组信息
     */
    fun getTeamInfo(token: String) : Observable<ResponseInfo> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).getTeamInfo(TokenReq(token))
    }

    fun getProjectTeamInfo(teamId: Int, token: String) : Observable<ResponseInfo> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).getProjectTeamInfo(teamId,TokenReq(token))
    }

    /*
        获取所在项⽬信息
     */
    fun getProjectInfo(token: String) : Observable<ResponseInfo> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).getProjectInfo(TokenReq(token))
    }

    /*
      更改项⽬状态
   */
    fun changeProjectStatus(token: String, status:String) : Observable<ResponseInfo> {
        return RetrofitFactory.instance.create(ProjectTeamApi::class.java).changeProjectStatus(ProjectStatusReq(token,status))
    }

}